package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController {
    @Autowired
    NursingPlanService nursingPlanService;


    /**
     * 1 查询所有护理计划
     */
    @GetMapping
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getAllPlan() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getAllPlan();
        return success(nursingPlanVos);
    }

    /**
     * 2 新增
     */
    @PostMapping
    @ApiOperation(value = "新增")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return success();
    }

    /**
     * 3 条件分页查询
     */
    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理计划名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "护理计划状态", required = false, dataType = "int", paramType = "query"),

    })
    public ResponseResult<PageResponse<NursingPlanVo>> selectByPage(Integer pageNum,
                                                                       Integer pageSize,
                                                                       String name,
                                                                       Integer status) {
        PageResponse<NursingPlanVo> pageInfo = nursingPlanService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);

    }




    /**
     * 4 根据id查询
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult<NursingPlanVo> selectById(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.selectById(id);
        return success(nursingPlanVo);

    }

    /**
     * 修改
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "修改")
    public ResponseResult modifyPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.modifyPlan(nursingPlanDto);
        return success();
    }


    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingPlanService.deleteById(id);
        return success();
    }


    /**
     * 启用禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingPlanService.enableOrDisable(id, status);
        return success();
    }





}
